package zmee.pur.src.formplugin;

import kd.bos.bill.AbstractBillPlugIn;
import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.dataentity.utils.ObjectUtils;
import kd.bos.servicehelper.BusinessDataServiceHelper;
import kd.scm.common.enums.BillStatusEnum;

import java.util.EventObject;
import java.util.Objects;

/**
 * @Author: xw
 * @Date: 2023/02/16/15:53
 * @Description: 开商务标加载时操作触发综合计算
 */
public class ComPareBillPlugin extends AbstractBillPlugIn {
    @Override
    public void afterBindData(EventObject e) {
        Object id = this.getModel().getValue("id");
        DynamicObject projectRule = BusinessDataServiceHelper.loadSingle(id, "src_project_rule");
        String billStatus = (String) this.getModel().getValue("billstatus");
        if (ObjectUtils.isEmpty(projectRule) || !Objects.equals(BillStatusEnum.SAVE.getVal(), billStatus)) {
            return;
        }
        DynamicObject extFilter = projectRule.getDynamicObject("extfilter");
        if (extFilter != null) {
            String number = extFilter.getString("number");
            if (!"negotiate004".equals(number)) {
                this.getView().invokeOperation("recalculates");
            }
        } else {
            this.getView().invokeOperation("recalculates");
        }
    }
}
